package com.ruoyi.web.controller.project;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.domain.ProjectEnvironment;
import com.ruoyi.project.service.IProjectEnvironmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 功能模块Controller
 *
 * @author yhg
 * @date 2022-10-18
 */
@RestController
@RequestMapping("/project/environment")
public class ProjectEnvironmentController extends BaseController
{
    @Autowired
    private IProjectEnvironmentService projectEnvironmentService;

    /**
     * 查询功能模块列表
     */
    @PreAuthorize("@ss.hasPermi('project:environment:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectEnvironment projectEnvironment)
    {
        startPage();
        List<ProjectEnvironment> list = projectEnvironmentService.selectProjectEnvironmentList(projectEnvironment);
        return getDataTable(list);
    }

    /**
     * 导出功能模块列表
     */
    @PreAuthorize("@ss.hasPermi('project:environment:export')")
    @Log(title = "功能模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectEnvironment projectEnvironment)
    {
        List<ProjectEnvironment> list = projectEnvironmentService.selectProjectEnvironmentList(projectEnvironment);
        ExcelUtil<ProjectEnvironment> util = new ExcelUtil<ProjectEnvironment>(ProjectEnvironment.class);
        util.exportExcel(response, list, "功能模块数据");
    }

    /**
     * 获取功能模块详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:environment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(projectEnvironmentService.selectProjectEnvironmentById(id));
    }

    /**
     * 新增功能模块
     */
    @PreAuthorize("@ss.hasPermi('project:environment:add')")
    @Log(title = "功能模块", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectEnvironment projectEnvironment)
    {
        return toAjax(projectEnvironmentService.insertProjectEnvironment(projectEnvironment));
    }

    /**
     * 修改功能模块
     */
    @PreAuthorize("@ss.hasPermi('project:environment:edit')")
    @Log(title = "功能模块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectEnvironment projectEnvironment)
    {
        return toAjax(projectEnvironmentService.updateProjectEnvironment(projectEnvironment));
    }

    /**
     * 删除功能模块
     */
    @PreAuthorize("@ss.hasPermi('project:environment:remove')")
    @Log(title = "功能模块", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(projectEnvironmentService.deleteProjectEnvironmentByIds(ids));
    }
}
